package runner;

import java.sql.SQLException;
import java.util.ArrayList;

import Operators.DrumOperator;
import Route.*;
import States.StationState;
import Templates.Operator;
import Templates.State;
import Algorithms.Algoritm;
import Algorithms.DepthSearch;
import Algorithms.Dijkstra;
import Algorithms.UniformCost;
import Algorithms.WidthSearch;
import Database.BazaDate;
import java.sql.ResultSet;

public class DateBD {

	/**
	 * @param args
	 */
	
	public static ContainerStatii cs = new ContainerStatii(new Statie(0, "Zero", 40, 40), new Statie(1, "Unu", 30,
			30), new Statie(2, "Doi", 40, 30), new Statie(3, "Trei", 50, 30), new Statie(4, "Patru", 20, 20), new Statie(5, "Cinci", 10, 10), new Statie(6, "Sase", 30, 10), new Statie(7, "Sapte", 35, 20));
	
	public static ContainerLegaturi cl = new ContainerLegaturi(new Legatura(cs.getStatie(0), cs.getStatie(1), 4),
			new Legatura(cs.getStatie(0), cs.getStatie(2), 4), new Legatura(cs.getStatie(0), cs
					.getStatie(3), 4), new Legatura(cs.getStatie(1), cs.getStatie(4), 4), new Legatura(
					cs.getStatie(2), cs.getStatie(7), 4), new Legatura(cs.getStatie(4), cs.getStatie(5),
					4), new Legatura(cs.getStatie(4), cs.getStatie(6),
					4));
 
	
	public static void main(String[] args) throws SQLException {
                BazaDate bd = new BazaDate();
                bd.conecteaza();
                ResultSet rez;
                rez = bd.doQuery("select * from statii");
                while (rez.next()) {
				System.out.print(rez.getString(1)+" "+rez.getString(3)+" "+rez.getString(2)+"\n");
			}
		// TO-DO
		// citire statii si legaturi din BAZA DE DATE si populate cele doua container-e de mai jos

		/*
		cs = new ContainerStatii(new Statie(0, "Zero", 123, 123), new Statie(1, "Unu", 234,
				234), new Statie(2, "Doi", 124, 231), new Statie(3, "Trei", 614, 214));

		cl = new ContainerLegaturi(new Legatura(cs.getStatie(0), cs.getStatie(1), 7),
				new Legatura(cs.getStatie(0), cs.getStatie(2), 9), new Legatura(cs.getStatie(0), cs
						.getStatie(3), 14), new Legatura(cs.getStatie(1), cs.getStatie(2), 10), new Legatura(
						cs.getStatie(1), cs.getStatie(3), 15), new Legatura(cs.getStatie(2), cs.getStatie(3),
						11), new Legatura(cs.getStatie(2), cs.getStatie(0), 21));
 */
		// TO-DO
		// citire tip algoritm si statie pornire respectiv destinatie din INTERFATA
		// afisare rezultate

		Algoritm d = new Dijkstra();

		Statie[] l = d.executa(cs.toVector(), cl.toVector(), cs.getStatie(7), cs.getStatie(0));

		for (Statie s : l) {
			//System.out.println(s.getCod() + " " + s.getNume());
		}

		StationState ex = new StationState(cs.getStatie(0));
		/**  Station States Initialize**/
		ArrayList<Operator<Statie>> drumOperators=DrumOperator.returnOperators();
		State<Statie> stationInitialState=ex.initalState();
		StationState.curenta = cs.getStatie(7);
		ArrayList<State<Statie>> stationFinalState=ex.finalStates();
		StationState.curenta = cs.getStatie(0);
		/** Station End **/
		
		String StationDepth="StationDepth.txt";
		String StationWidth="StationWidth.txt";
		String StationUniformCost="StationUniformCost.txt";
		
		 /** Station Execution **/
		DepthSearch<Statie> stationDepth=new DepthSearch<Statie>(stationInitialState,stationFinalState,drumOperators,StationDepth);
		WidthSearch<Statie> stationWidth=new WidthSearch<Statie>(stationInitialState,stationFinalState,drumOperators,StationWidth);
		stationDepth.executeAlgorithm();
                stationWidth.executeAlgorithm();
                /** Station Execution End **/
	    
		UniformCost inc = new UniformCost(DateBD.cs.getStatie(7),DateBD.cs.getStatie(0),StationUniformCost);
		inc.executeAlgorithm();

	}
}
